import time
import operator


def ecn_no_num(be):
    ecn_time = time.strftime('%Y%m%d', time.localtime(time.time()))
    if be is None:
        ecn_no = 'ECN_C' + str(ecn_time) + '0001'
    elif len(be) != 17:
        ecn_no = 'ECN_C' + str(ecn_time) + '0001'
    else:
        sp = be[5:13]
        kp = be[13:]
        if operator.eq(sp, ecn_time):
            kp_new = int(kp) + 1
            ecn_no = be[:13] + str(kp_new).rjust(4, '0')
        else:
            ecn_no = 'ECN_C' + str(ecn_time) + '0001'
    return ecn_no


if __name__ == '__main__':
    # b = 'ECN_C201712290001'
    b = 'ECN_C2017'
    a = ecn_no_num(None)
    print(a)
    #
    # a = ['hhh', 'ppp', 'nnn', '要求']
    # kk = '要求'
    # if kk not in a:
    #     print('ll')
    #
    # # a = {2:[1,9]}
    # # b = {6:[3,2]}
    # # c = []
    # # c.append(a)
    # # c.append(b)
    # # # print(c)
    # # for i in c:
    # #     for ke, ve in i.items():
    # #         print(ke)
    # #         for k in ve:
    # #             print(k)
    # a = [1,4,5]
    # b = [7,3,1]
    # c = []
    # c.append(a)
    # c.append(b)
    # print(c)
    # for i in c:
    #     print(i[0])
    #     print(i[1])
    #     Tbdr.object.filter(id=i[0]).update(a=i[1],b=i[2])
    #     # print(i)
    #     # print(i[0])
    #     # print(i[1])
    #     # print(i[2])
    #
    #
    #     # a = {2:[1,9]}
    # # b = {6:[3,2]}
    # # c = []
    # # c.append(a)
    # # c.append(b)
    # # # print(c)
    # # for i in c:
    # #     for ke, ve in i.items():
    # #         print(ke)
    # #         for k in ve:
    # #             print(k)
    #
    # a = [{'href': '/fileData2/ST/file_manager/drawing/4f39414e-f121-11e7-9965-000c29291d2a.pdf', 'id': 37},
    #  {'href': '/fileData2/ST/file_manager/drawing/472ac5e0-f121-11e7-9b6e-000c29291d2a.pdf', 'id': 33},
    #      {'href': '/fileData2/ST/file_manager/drawing/472ac5e0-f121-11e7-9b6e-000c29291d2a.pdf', 'id': 39},
    #      {'href': '/fileData2/ST/file_manager/drawing/472ac5e0-f121-11e7-9b6e-000c29291d2a.pdf', 'id': 3}]
    # pl = []
    # kk = []
    # nn = []
    # for i in a:
    #     pl.append(i['id'])
    # pl.sort()
    # print(pl)
    # for i in pl:
    #     for j in a:
    #         if int(i) == int(j['id']):
    #             kk.append(j)
    #             nn.append(j['href'])
    # print(kk)
    # print(nn)
    # for ki in kk:
    #     nn.append(ki[0])
    # print(nn)
#
# a = '''[{"file_type": 1, "file_size": 585161, "drawing_type": "開刃圖", "drawing_type_id": 167,
#       "create_time": "2018-01-04 15:30:59", "id": 9,
#       "file_path": "file_manager/drawing/3603fcfa-f121-11e7-a7d3-000c29291d2a.pdf", "cus": 0,
#       "uploader": "F1330314(周心有)", "customer": null, "dev_type": "gg", "file_name": "123.pdf", "dev_type_id": 1,
#       "project": 1, "$$hashKey": "object:37", "_drawing_type_id": "167", "_dev_type_id": "1"},
#      {"file_type": 1, "file_size": 585161, "drawing_type": "逃料圖", "drawing_type_id": 167,
#       "create_time": "2018-01-04 15:30:59", "id": 11,
#       "file_path": "file_manager/drawing/35fd34c4-f121-11e7-a7d3-000c29291d2a.pdf", "cus": 0,
#       "uploader": "F1330314(周心有)", "customer": null, "dev_type": "哈", "file_name": "123 - 副本.pdf", "dev_type_id": 1,
#       "project": 1, "$$hashKey": "object:38", "_drawing_type_id": "167"},
#      {"file_type": 0, "file_size": 93576, "upload_time": "2018-01-04 17:38:19",
#       "file_name": "FG次集團大陸地區2017年12月-2018年3月行事曆排配.pdf", "id": 49,
#       "url": "file_manager/drawing/ffc20f62-f132-11e7-a9cc-005056b624a8.pdf", "uploader": "F1331855(謝芷晗)",
#       "$$hashKey": "object:82", "_drawing_type_id": "169", "drawing_type_id": 169, "_dev_type_id": "1",
#       "dev_type_id": 1}]
# '''
# b = a.replace('null', 'None')
# print(eval(b))

# print(eval(b))

# import requests
# import urllib3
# f = requests.get('http://10.149.3.130:8000/customer/cm')
#
# url = 'http://10.149.3.130:8000/ac/login'
# payload = {'username':'F1330314', 'password':'F1330314'}
# m = urllib3.connection_from_url(url=url)
# m.request('post', url, payload)
# print(m)















# @api_view(http_method_names=["GET", "PUT", "POST", "DELETE"])
# @wrapp
# def Pro_Draft(request):
#     """
#     ok
#     :param request:
#     :return:
#     """
#     content = {"payload": [], "status": 1, "errmsg": None}
#
#     if request.method == 'GET':
#         try:
#             search = request.GET.get("search", None)
#             page_num = request.GET.get("page", None)
#             create_people = request.user.username + "(" + request.user.last_name + ")"  # 获取当前登陆用户名
#             if create_people:
#                 create_people = str(create_people).split('(')[0]
#             if search:
#                 res = models.TbProjectPaper.objects.filter(p_confirm=0).filter(create_people=create_people).filter(Q(ecn_no__contains=search) | Q(version__contains=search) |
#                                                    Q(case_name__contains=search) | Q(custters_spec__contains=search) |
#                                                    Q(uploader__contains=search) | Q(priority__contains=search) |
#                                                    Q(id__contains=search) | Q(st_site__contains=search)|
#                                                     Q(cutter_type__contains=search) | Q(stage_type__contains=search)
#                                                     )
#             else:
#                 res = models.TbProjectPaper.objects.filter(p_confirm=0)
#                 # print(res[0]['id'])
#             if page_num:
#                 page_class_k = Paginator(res, 20)
#             else:
#                 page_class_k = Paginator(res, len(res) + 1)
#                 page_num = 1
#
#             select_data_k = page_class_k.page(page_num)#第n页中的内容
#             content["payload"] = {"data": [], "page": {}}  # 定义payload的输出格式
#             if select_data_k:#循环输出第n页中的内容
#                 for i in select_data_k:
#                     content['payload']['data'].append({
#                         'id':i.id,
#                         'cutter_type_id':i.cutter_type,
#                         'priority':i.priority,
#                         'project_name':i.project_name,
#                         'custters_spec':i.custters_spec,
#                         'stage_type':i.stage_type,
#                         'secrecy_level':i.secrecy_level,
#                         'uploader':i.uploader,
#                         'drawing_type_id':i.drawing_type,
#                         'p_confirm':i.p_confirm,
#                         'ecn_no':i.ecn_no,
#                         'cutter_type':i.cutter_type,
#                         'dev_type':i.dev_type,
#                         'modify_time':(i.modify_time).strftime("%Y-%m-%d %H:%M:%S"),
#                         'create_time':(i.create_time).strftime("%Y-%m-%d %H:%M:%S"),
#                         'upload_time':(i.upload_time).strftime("%Y-%m-%d %H:%M:%S"),
#                         'definer_name':i.definer_name,
#                         'stage_type_id':i.stage_type,
#                         'version':i.version,
#                         'drawing_type':i.drawing_type,
#                         'case_no':i.case_no,
#                         'st_site':i.st_site,
#                     })
#
#             content["payload"]["page"] = {'count': page_class_k.count, 'page': int(page_num),
#                                           'page_number': page_class_k.page_range[-1]}
#
#         except Exception as e:
#             content['status'] = 0
#             content['errmsg'] = str(e)
#             content['payload'] = []
#
#
#     # if request.method == 'GET':
#     #     try:
#     #         mp = models.TbProjectPaper.objects.filter(p_confirm=0).values()
#     #         p_data = []
#     #         for j in mp:
#     #             p_data.append({
#     #                 'id': j['id'],
#     #                 'cutter_type_id': j['id_cutter_type'],
#     #                 'priority': j['priority'],
#     #                 'project_name': j['project_name'],
#     #                 'custters_spec': j['custters_spec'],
#     #                 'stage_type': j['stage_type'],
#     #                 'secrecy_level': j['secrecy_level'],
#     #                 'uploader': j['uploader'],
#     #                 'drawing_type_id': j['id_drawing_type'],
#     #                 'p_confirm': j['p_confirm'],
#     #                 'ecn_no': j['ecn_no'],
#     #                 'cutter_type': j['cutter_type'],
#     #                 'dev_type': j['dev_type'],
#     #                 'modify_time': (j['modify_time']).strftime('%Y-%m-%d %H:%M:%S'),
#     #                 'dev_type_id': j['id_dev_type'],
#     #                 'create_time': (j['create_time']).strftime('%Y-%m-%d %H:%M:%S'),
#     #                 'definer_name': j['definer_name'],
#     #                 'stage_type_id': j['id_stage_type'],
#     #                 'version': j['version'],
#     #                 'upload_time': (j['upload_time']).strftime('%Y-%m-%d %H:%M:%S'),
#     #                 'drawing_type': j['drawing_type'],
#     #                 'case_no': j['case_no'],
#     #                 'st_site': j['st_site'],
#     #             })
#     #
#     #         content['payload'] = p_data
#     #         content['errmsg'] = ''
#     #         content['status'] = 1
#     #     except Exception as e:
#     #         content['payload'] = []
#     #         content['errmsg'] = str(e)
#     #         content['status'] = 0


#
# @api_view(http_method_names=["GET", "PUT", "POST", "DELETE"])
# @wrapp
# def Dev_type(request):
#     """
#     道具接口
#     :param request:
#     :return:
#     """
#     content = {"payload": [], "status": 1, "errmsg": None}
#     if request.method == 'GET':
#         try:
#             data = models.TbTypeDevice.objects.filter().all()
#             content['payload'] = data
#             content['errmsg'] = ''
#             content['status'] = 1
#         except Exception as e:
#             content['payload'] = []
#             content['errmsg'] = str(e)
#             content['status'] = 0
#     if request.method == 'POST':
#         try:
#             dev_name = request.POST.get('dev_name')
#             create_people = request.user.username + "(" + request.user.last_name + ")"  # 获取当前登陆用户名
#             create_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))  # 创建时间
#             models.TbTypeDevice.objects.create(dev_name=dev_name, create_people=create_people, create_time=create_time)
#             content['payload'] = 'add success'
#             content['errmsg'] = ''
#             content['status'] = 1
#         except Exception as e:
#             content['payload'] = []
#             content['errmsg'] = str(e)
#             content['status'] = 0
#     return content
#
# @api_view(http_method_names=["GET", "PUT", "POST", "DELETE"])
# @wrapp
# def Dev_typepk(request, pk):
#     content = {"payload": [], "status": 1, "errmsg": None}
#     if request.method == 'DELETE':
#         try:
#             models.TbTypeDevice.objects.filter(id=pk).delete()
#             content['payload'] = 'delete success'
#             content['errmsg'] = ''
#             content['status'] = 1
#         except Exception as e:
#             content['payload'] = []
#             content['errmsg'] = str(e)
#             content['status'] = 0
#     return content


base_str = "我已经将我的狗狗送人了"
bytes_utf_8 = base_str.encode(encoding="utf-8")
str_from_utf_8 = bytes_utf_8.decode(encoding="utf-8")
print(base_str)
print(bytes_utf_8)
print(str_from_utf_8)